<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
<script src="${pageContext.request.contextPath}/layui/jquery2.1.1.js"></script>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>采购单审核</li>
    <li>审核</li>
  </ul>
</div>
<form class="layui-form" action="">
<div class="formbody">
  <div class="formtitle"><span>采购单审核</span></div>
  <div class="layui-form-item">
    <label class="layui-form-label">采购单编号</label>
    <div class="layui-input-inline" >
      <input id="number" name="number" type="text" value="" readonly="readonly" class="layui-input" />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">采购时间</label>
    <div class="layui-input-inline" >
      <input id="poTime" name="poTime" type="text" value="" readonly="readonly" class="layui-input" />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">总金额</label>
    <div class="layui-input-inline" >
      <input id="amount" name="amount" type="text" value="" readonly="readonly" class="layui-input" />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">操作人</label>
    <div class="layui-input-inline" >
      <input id="userPerson" name="userPerson" type="text" value="" readonly="readonly" class="layui-input" />
    </div>
  </div>
  <table id="PurchaseTable" lay-filter="PurchaseTable"></table>
  <div class="layui-form-item">
    <label class="layui-form-label">审核意见</label>
    <div class="layui-input-inline" >
      <input type="area" id="content" name="content" value="" class="layui-input" />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">审核状态</label>
    <div class="layui-input-inline" >
      <select id="status" name="status">
        <option value="0">请选择</option>
        <option value="1">未审核</option>
        <option value="2">审核中</option>
        <option value="3">审核通过</option>
        <option value="4">审核未通过</option>
      </select>
    </div>
  </div>
  <div class="layui-btn-container">
    <button lay-submit lay-filter="formDemo"  class="layui-btn btn-add">审核</button>
  </div>
</div>
</form>
<script type="text/javascript">
  $(function () {
    //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
    var parent_json = eval('('+parent.json+')');
    $("#number").val(parent_json.number);
    $("#poTime").val(parent_json.poTime);
    $("#amount").val("￥"+parent_json.amount);
    $("#userPerson").val(parent_json.userPerson);
    $("#status").val(parent_json.status);
    $("#auditor").val(parent_json.auditor);
    $("#auditTime").val(parent_json.auditTime);
    $("#poTime").val(parent_json.poTime);
  });

  layui.use(['table', 'form'], function () {
    var table = layui.table,
            $ = layui.jquery,
            form = layui.form;
    //展示已知数据
    table.render({
      elem: '#PurchaseTable'
      , url: 'http://localhost:8080/PurchaseOrderDetails/getPurchaseOrderDetailsList?number='+$("#number").val() //数据接口
      , cols: [[ //表头
        {field: 'orderId', title: '序号', width: 105, align: "center"}
        , {field: 'name', title: '品牌', width: 105,align: "center"}
        , {field: 'type', title: '类型', width: 105, align: "center"}
        , {field: 'mode', title: '型号', width: 105, align: "center"}
        , {field: 'manufacturer', title: '厂商', width: 105, align: "center"}
        , {field: 'num', title: '数量', width: 105, align: "center"}
        , {field: 'units', title: '单位', width: 105, align: "center"}
        , {field: 'price', title: '单价', width: 105, align: "center"}
        , {field: 'amounts', title: '金额', width: 113, align: "center"}
      ]]
    });
    form.render();
    //监听提交
    form.on('submit(formDemo)', function(){
      $.ajax({
        url: "/PurchaseOrder/updatePurchaseExamine",
        data: {
          number: $('#number').val(),
          content: $('#content').val(),
          status: $('#status').val(),
        },
        type: 'post',
        dataType: 'json',
        success: function (resp) {
          layer.closeAll();
          layer.msg(resp.message, {icon: 6});
        },
        error: function () {
          layer.closeAll();
          layer.msg('系统错误，请联系管理员', {icon: 5});
        }
      });
      $(function (){
        layer.closeAll();
        table.reload('PurchaseTable', {
          where: {},
          page: {
            curr: 1 //重新从第 1 页开始
          }
        });
      });
      return false;
    });
  });
</script>
</body>
</html>
